import React, { Component } from 'react';
import { StyleSheet, StatusBar, View, Image, Text, TouchableOpacity, FlatList, RefreshControl, Platform, BackHandler, ImageBackground, DeviceEventEmitter } from 'react-native';
import Colors from '../constants/Colors';
import { unitWidth, width } from '../constants/AdapterUtil';
import { MyHeader } from '../components/MyHeader';
import { CommonModal, UpdateModal } from '../components/Modal';
import NavigationService from '../constants/NavigationService';
import { CacheModule } from '../constants/CustomModules';
import { remove, LoginToken } from '../constants/MyStorage';
import { show } from '../constants/Toast';
import { SettingItem } from '../components/Item';
import { SubmitButton1 } from '../components/Button';

export default class SettingScreen extends Component {
    constructor(props) {
        super(props)

        const { navigation } = this.props;
        this.state = {
            cacheSize: '0K',
        }
    }

    componentDidMount() {
        if (Platform.OS == 'android') {
            CacheModule.getCache(size => {
                this.setState({
                    cacheSize: size
                })
            })
        } else {
            // CacheModule.getCache((size) => {
            //     console.log('123'+ size.currentsize);
            //     this.setState({
            //         cacheSize: size.currentsize
            //     })
            // });
        }

    }

    render() {
        return (
            <View style={{ backgroundColor: Colors.colorF7, flex: 1, alignItems: 'center' }}>
                <MyHeader title='设置' leftImg={require('../res/ic_arrow_left.png')} leftClick={() => { this.props.navigation.pop() }} />
                <SettingItem
                    style={{ marginTop: 7 * unitWidth, }}
                    value={this.state.cacheSize}
                    title='清除缓存'
                    onPress={() => {
                        CacheModule.clearCache();
                        this.setState({
                            cacheSize: '0K'
                        })
                    }} />
                <SettingItem
                    style={{ marginTop: 7 * unitWidth, }}
                    value={Platform.OS == 'android' ? global.currentAndroidVersion : global.currentIosVersion}
                    title='版本更新'
                    onPress={() => {
                        // this.refs.UpdateModal.showModal();
                        show('当前已是最新版本')
                    }} />
                <SettingItem
                    style={{ marginTop: 7 * unitWidth, }}
                    title='意见反馈'
                    onPress={() => {
                        this.props.navigation.navigate('Opinion')
                    }} />
                <SettingItem
                    style={{ marginTop: 7 * unitWidth, }}
                    title='关于我们'
                    onPress={() => {
                        this.props.navigation.navigate('About')
                    }} />
                <SubmitButton1 style={{ marginTop: 202 * unitWidth }} text='退出登录' onPress={() => {
                    this.refs.CommonModal.showModal();
                }} />
                <CommonModal ref='CommonModal' title='确定退出？' comfirmText='确定' cancelText='取消'
                    comfirmClick={() => {
                        global.token = undefined;
                        global.userInfo = undefined;
                        global.companyInfo = undefined;
                        remove(LoginToken);
                        NavigationService.navigate('Login');
                    }} />
                <UpdateModal ref='UpdateModal' />
            </View>
        );
    }
}